﻿@model Springwater.Business.ViewModels.BorvizEditModel

@{
    ViewBag.Title = "Edit";
    int index = 0;
}

<h2>Edit</h2>
<span>@Html.ActionLink("Teljes nezet", "Index", new { id = Model.Id })</span>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset class="EditBorviz">
        <legend>BorvizEditModel</legend>

        @Html.HiddenFor(m => m.Id)
        <table style="width:100%;">
            <tr>
                <td>@Html.ActionLink("Fenykepek", "ManagePicture", new { borvizId = Model.Id })</td>
                <td></td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Elnevezes 1:</label></td>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.Elnevezes1)
                        @Html.ValidationMessageFor(model => model.Elnevezes1)
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Elnevezes 2:</label></td>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.Elnevezes2)
                        @Html.ValidationMessageFor(model => model.Elnevezes2)
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Elnevezes 3:</label></td>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.Elnevezes3)
                        @Html.ValidationMessageFor(model => model.Elnevezes3)
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Kod:</label></td>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.Kod)
                        @Html.ValidationMessageFor(model => model.Kod)
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Tajegyseg:</label></td>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.Tajegyseg)
                        @Html.ValidationMessageFor(model => model.Tajegyseg)
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Eredet:</label></td>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.Eredet)
                        @Html.ValidationMessageFor(model => model.Eredet)
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Leiras:</label></td>
                <td>
                    <div class="editor-field">
                        <textarea id="leiras" name="leiras">@Html.Raw(Model.Leiras)</textarea>
                        @*@Html.Hidden("Leiras")*@
@*                        @Html.EditorFor(model => model.Leiras)
                        @Html.ValidationMessageFor(model => model.Leiras)*@
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Vizgyujto:</label></td>
                <td>
                    <table class="Vizgyujto">
                        <tr>
                            @foreach (var vizgyujto in Model.VizgyujtoList)
                            {
                                if (index % 10 == 0) {@Html.Raw("<td>")}                                
                                @Html.Hidden(string.Format("VizgyujtoBoolList[{0}]", index), Model.VizgyujtoIdList.Contains(vizgyujto.Id) ? true : false, new { id = string.Format("VizgyujtoBoolList[{0}]", index) })
                                @Html.CheckBox(string.Format("CheckBoxVizgyujtoId_{0}", index++), Model.VizgyujtoIdList.Contains(vizgyujto.Id))
                                <label class="Text">@vizgyujto.Nev</label>
                                <br />
                                if (index % 10 == 0) {@Html.Raw("</td>")}
                            }
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <label class="Text">GPS Nord:</label></td>
                <td>@Html.EditorFor(m => m.GpsNord)</td>
            </tr>
            <tr>
                <td>
                    <label class="Text">GPS Est:</label></td>
                <td>@Html.EditorFor(m => m.GpsEst)</td>
            </tr>
            <tr>
                <td>
                    <label class="Text">Magassag:</label></td>
                <td>@Html.EditorFor(m => m.Magassag)</td>
            </tr>
        </table>

        <p>
            <input id="submitButton" type="submit" value="Save" />
        </p>
    </fieldset>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    <script type="text/javascript">
        $(document).ready(Init);

        function Init() {
            $("[name*='CheckBoxVizgyujtoId_']").change(function () {

                var id = $(this).attr("Id").replace("CheckBoxVizgyujtoId_", "");

                if ($(this).is(":checked")) {
                    $("#VizgyujtoBoolList\\[" + id + "\\]").val("True");
                }
                else {
                    $("#VizgyujtoBoolList\\[" + id + "\\]").val("False");
                }
            });

            tinymce.init({
                selector: "textarea#leiras",
                theme: "modern",
                plugins: [
                    "advlist autolink lists link image charmap print preview hr anchor pagebreak",
                    "searchreplace wordcount visualblocks visualchars code fullscreen",
                    "insertdatetime media nonbreaking save table contextmenu directionality",
                    "emoticons template paste textcolor"
                ],
                toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
                toolbar2: "print preview media | forecolor backcolor emoticons",
                image_advtab: true,
                templates: [
                    { title: 'Test template 1', content: 'Test 1' },
                    { title: 'Test template 2', content: 'Test 2' }
                ],
                encoding: "xml",
                setup: function(editor) {
                        editor.on('SaveContent', function(e) {
                            e.content = e.content.replace(/&#39/g, "&apos");
                        });
                },
                width: '100%',
                height: 300,
                body_class: "leiras",
                content_css: "Content/Site.css"
                
            });

            $("#submitButton").click(function () {
                //alert(tinyMCE.activeEditor.getContent());
                tinyMCE.triggerSave();
                //$("[name=Leiras]").val(tinyMCE.activeEditor.getContent());
                //return false;
            });

        }
    </script>
}
